package 一对一通信;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class RecevieDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			DatagramSocket ds=new DatagramSocket(9090);
			while(true){
				byte[]data=new byte[1024];
				DatagramPacket dp=new DatagramPacket(data, data.length);
				ds.receive(dp);
				byte[] data2 = dp.getData();
				String str=new String(data2,0,dp.getLength());
				if(str=="886") {
					break;
				}
				String name = dp.getAddress().getHostName();
				String ip = dp.getAddress().getHostAddress();
				System.out.println(name+"-"+ip+"-"+str);
			}
			ds.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
